﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Water.Web.Controls.Office.Excel.Util
{
    public class Sheet
    {
        /// <summary>
        /// 输出创建sheet的VBScript脚本
        /// </summary>
        /// <param name="sheetNum">的几个sheet</param>
        /// <param name="sheetTitle">sheet标题</param>
        /// <returns>创建sheet的VBScript脚本</returns>
        public static string CreateNewSheet(int sheetNum, string sheetTitle)
        {
            string _ret = "\nIf Excel.Sheets.Count <" + sheetNum + " Then\n"
                + "  Excel.Sheets.Add\n"
                + "Else\n"
                + "  Excel.Sheets(" + sheetNum + ").Select\n"
                + "End If\n";

            if (!string.IsNullOrEmpty(sheetTitle))
            {
                _ret += "\nWith Excel.ActiveSheet\n"
                    + "  .Select\n"
                    + "  .Name=\""+sheetTitle+"\"\n"
                    +"End With\n";
            }

            return _ret;
        }
    }
}
